﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sio.Mdm.Types
{
    /// <summary>
    /// Interface that should be implemented by session providers
    /// </summary>
    public interface ISessionProvider
    {
        /// <summary>
        /// Return session for currently logged user
        /// </summary>
        /// <returns>Instance of <see cref="Session"/></returns>
        Session GetSession();
    }

    /// <summary>
    /// Factory to get current session for logged user
    /// </summary>
    public static class SessionFactory
    {
        #region Fields
        private static ISessionProvider CurrentProvider; 
        #endregion

        #region Properties
        public static Session Session
        {
            get
            {
                return CurrentProvider == null ? Session.Empty : CurrentProvider.GetSession();
            }
        } 
        #endregion

        #region Methods
        public static void RegisterProvider(ISessionProvider provider)
        {
            CurrentProvider = provider;
        }
        #endregion
    }
}
